{%include file="header.html"%}
<style>
td {  font-weight: bold;}
</style>
<body>
<div class="fixed-bar">
  <div class="item-title">
    <h3>设置商品库存</h3>
  </div>
</div>
<div class="fixed_bottom">
  <form method="post" action="goods.php" id="aspnetForm" name="form1" enctype="multipart/form-data">
    <div class="active_body" style="display:block;">
      <input type="hidden" name="act" value="add_products">
      <input type="hidden" name="goods_id" value="{%$goods.goods_id%}">
      <table id="product_desctab" style=" width:100%;" cellpadding="0" cellspacing="0" border="1" class="table tb-type2">
      	<th colspan="20" align="center" style="background:#E5F6FE;"><span style="color:#000000;">商品名称：{%$goods.goods_name%}&nbsp;&nbsp;&nbsp;&nbsp;货号：{%$goods.goods_sn%}</span></th>
        <tr>
        	{%foreach from=$goods_products item=products%}
            <td>{%$products.name%}</td>
            {%/foreach%}
        	<td width="200">货号</td>
          <td width="200">库存</td>
          <td width="100">操作</td>
        </tr>
        {%if $product%}
          {%foreach from=$product item=products key=kv%}
            <tr id="tr">    
                 {%foreach from=$products.goods_attr item=vlist key=a%}  
                 <td>
                    <input type="hidden" name="goods_attr[{%$a%}][]" value="{%$vlist.id%}">
                    <span>{%$vlist.name%}</span>
                 </td>
                 {%/foreach%}
              <td><input style="height:20px; width:150px;" value="{%$products.product_sn%}" type="text" name="product_sn[]" required/></td>
              <td><input style="height:20px; width:150px;" value="{%$products.product_number%}" class="goods_attrtext" type="text" name="product_number[]" required/></td>
              <td><a href="javascript:" onclick="removeImg(this)">[-]</a></td>
            </tr>
          {%/foreach%}
        {%/if%}
        <tr id="tr">
          {%foreach from=$goods_products item=list key=k%}
           <td>
            <select name="goods_attr[{%$k%}][]"  required>
              {%foreach from=$list.val item=vlist key=a%}
              <option  required value="{%$vlist.goods_attr_id%}">{%$vlist.attr_value%}</option>   
              {%/foreach%}
            </select>
          </td>
          {%/foreach%}
          <td><input style="height:20px; width:150px;" type="text" name="product_sn[]"/></td>
          <td><input style="height:20px; width:150px;" class="goods_attrtext" type="text" name="product_number[]"/></td>
          <td><a href="javascript:" onclick="addImg(this)">[+]</a></td>
        </tr>
      </table>
    </div>
    <div style="text-align:center">
      <div class="style1">&nbsp;</div>
      <div> <a href="JavaScript:void(0);" class="btn" onclick="reset()"><span>重置</span></a> <a href="JavaScript:void(0);" class="btn" onclick="$('#tj').click()"><span>确认提交</span></a> </div>
    </div>
    <input type="reset" id="cz" style="display: none;">
    <input type="submit" id="tj" style="display:none;">
  </form>
</div>

</body>
<script>
/*
 *商品不同属性对应库存配置
*/
function setattr(obj, key, attrval, attrid, goodsid){
	/*取得当前选中的属性*/
	var tt=$(obj).siblings("input[type=checkbox]").is(":checked");
	var num=0;
	if($(obj).is(":checked")){
		num++;
		var str ="<input alt='"+key+"' id='"+attrid+"' value='"+attrval+"' />";
		$(".attr_conc").html(str);
	}
	if(tt){num++;}
	$(obj).siblings("input[class^=attr_num]").val(num);
	var nn=$(obj).parents("tr").siblings().length;
	for(i=0;i<nn;i++){
		var tt=$(".attr_num"+i).val();
		//当有属性没有选中的时候
		if(tt<1){var ck=1;}
	}
	//将选中的属性存储
	
	//判断是否选中完整规格
	if(ck==1){
		var sms="<tr><td colspan='20'>请选择完整数据！</td></tr>";
		$(".attr_consx").html(sms);
	}else{
		
		$(".attr_consx").html("");
	}
}
/*点击+添加库存规格*/
function addImg(obj){
  vala=$(obj).parent().prev().children("input").val();
  valb=$(obj).parent().prev().prev().children("input").val();
  if(valb==''){
      $(obj).parent().prev().prev().children("input").focus();
      return false;
  }else if(vala==''){
      $(obj).parent().prev().children("input").focus();
      return false;
  }
  var con=$(obj).parents("#tr").html();
  var a='<a href="javascript:" onclick="removeImg(this)">[-]</a>';
  var ya='<a href="javascript:" onclick="addImg(this)">[+]</a>';
  con=con.replace(ya,a);
  con="<tr>"+con+"</tr>";
  $(obj).parents("#product_desctab").append(con);
}
/*点击-号取消库存规格*/
function removeImg(obj){ 
  $(obj).parents("tr").remove();
}

</script>
</html>